package bussinessService.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import module.Content;
import utils.DateUtil;
import bussinessService.contentBussinessService;
import domain.vo.ContentQueryObject;
import domain.vo.ContentVO;
import domain.vo.queryObject;

public class ContentBussinessServiceImpl implements contentBussinessService{

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#deleteT(int)
	 */

	public void deleteT(int id) throws SQLException {
		
		contentService.deleteT(id);
	}

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#getAll()
	 */
	public List<ContentVO> getAll() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#getById(java.lang.String)
	 */
	public Content getById(String id) throws SQLException {
		// TODO Auto-generated method stub
		return contentService.getById(id);
	}

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#merageObject(java.lang.Object)
	 */
	public void merageObject(Content content) throws SQLException {
		if (content.getId() == 0) {
			contentService.insertObject(content);
		} else {
			contentService.updateObject(content);
		}
		
	}

	public int countByQueryObject(queryObject queryObject) throws SQLException {
		// TODO Auto-generated method stub
		return contentService.countByQueryObject(queryObject);
	}

	public List<ContentVO> getObjectByQueryObject(queryObject queryObject) throws SQLException {
		List<ContentVO> tempVOS = new ArrayList<ContentVO>();
		List<Content> results =contentService.getObjectByQueryObject(queryObject);
		for (Content c : results) {
			ContentVO vo = new ContentVO();
			vo.setContent(c.getContent());
			vo.setId(c.getId());
			vo.setPublisher(c.getPublisher());
			vo.setTitle(c.getTitle());
			vo.setEditable(c.getPublisher().equals(((ContentQueryObject)queryObject).getE_sn()));
			vo.setCreatetime(DateUtil.date2String(c.getCreatetime(),DateUtil.YYYY_MM_DD_HH_mm_ss));
			tempVOS.add(vo);
		}
		return tempVOS;
	}

}
